home *** CD-ROM | disk | FTP | other *** search
- /* 0:18:24 3/2/1986 */
-
- #include <stdio.h>
-
- FILE *fi, *fo;
- int lc, pagelen, p;
-
- #define FF '\014'
-
- main(argc, argv)
- int argc;
- char *argv[];
- {
- int c;
- extern int p;
- char s[80], *spt;
-
- if(argc == 1)
- {
- printf("Usage: TWOSIDED filname.ext\n");
- return;
- }
- else if((fi = fopen(argv[1], "r")) == NULL)
- {
- printf("Cannot find %s!\n", argv[1]);
- return;
- }
- else
- {
- fo = fopen("LPT1:","w");
- printf("Two sided printing utility.\n\n");
- printf("Written by Louis-Carl Lalonde.\n\n");
- printf("This utility will help you print you documents on both side of the\n");
- printf("page. It will first print all the odd numbered pages, then after\n");
- printf("you have reversed the paper, the even numbere ones.\n\n");
- printf("Do you want page numbers to be printed (Y/N) (default Y) ");
- p = getch();
- putch(p);
- if (p > 96)
- p -= 32; /* change to uppercase */
- printf("\n\nPlease enter maximum number of lines (default 55): ");
- gets(s);
- stcd_i(s, &c);
- if(c <= 0)
- pagelen = 55;
- else
- pagelen = c;
- spt = (p != 'N') ? "Yes" : "No";
- printf("\n\nPage numbers: %s", spt);
- printf("\nLines per page: %3d", pagelen);
- if (p != 'n' && p != 'N')
- pagelen -= 3;
- printf("\n\nPlease lign up your printer and hit any key to continue.\n");
- printf("CTRL-C or CTRL-BREAK will abort.\n");
- getch();
-
- printpag(1);
- fclose(fo);
- printf("\n\007Now finished with odd numbered pages.\n");
-
- printf("Please remove paper and reinsert on reverse side.\n");
- printf("Hit any key to continue. CTRL-C (CTRL-BREAK) will abbort\n");
- getch();
- fo = fopen("LPT1:","w");
- printpag(0);
- fprintf(fo, "\033@");
- fclose(fo);
- fclose(fi);
- return;
- }
- }
-
- printpag(s)
- int s;
- {
- extern int lc;
- int line, page;
-
- rewind(fi);
- lc = 0;
-
- if( s == 1) /* odd pages */
- {
- page = 1; /* page counter reset */
- while(wp(page++) != NULL)
- {
- if( sp() == NULL ) /* NULL if eof */
- break;
- page++; /* skip two page numbers */
- }
- }
- else /* even pages, second pass */
- {
- page = 2;
- while(sp() != NULL)
- {
- if(wp(page++) == NULL)
- break;
- page++;
- }
- }
- }
-
- wp(page)
- int page; /* page number */
- {
- int c, line;
- extern int lc, p;
-
- if (p != 'N')
- fprintf(fo, "%37s%3d -\n\n\n", "-", page);
-
- for ( line = 0; line < pagelen; line++)
- {
- while( (c = fgetc(fi)) != '\n' && c != FF && c != EOF)
- fputc(c, fo);
- if(c == EOF)
- {
- fputc(FF, fo);
- return(NULL);
- }
- fputc(c, fo);
- lc++;
- if (c == FF)
- return(lc);
- }
- fputc(FF, fo);
- while((c = fgetc(fi)) == '\n') /* skip empty lines */
- lc++;
- ungetc(c, fi);
- return(lc);
- }
-
- sp() /* skip page function */
- {
- int line, c;
- extern int lc;
-
- for ( line = 0; line < pagelen; line++)
- {
- while( (c = fgetc(fi)) != '\n' && c != FF && c != EOF)
- ;
- if(c == EOF)
- return(NULL);
- lc++;
- if (c == FF)
- return(lc);
- }
- while((c = fgetc(fi)) == '\n') /* skip empty lines */
- lc++;
- ungetc(c, fi);
- return(lc);
- }